$def with (mb, template=None, header_title="", page=None)

$ mb.component_times['TotalTime'] = time()

$ header_title = header_title or mb.key

$var title: $header_title

<div class="mybooks">

  $:mb.render_sidebar()

  $ css = 'no-padding' if mb.key == 'mybooks' else ''
  <div class="mybooks-details $css">

    $ mb.component_times['Details header'] = time()
    <header>
      <div class="breadcrumb-wrapper">
        $# Only show breadcrumbs when we're not on mybooks
        <div class="account-breadcrumb">
          <a href="$mb.user.key" class="username-avatar"><img src="$(mb.user.key)/avatar" class="account-avatar"></a>
          <h2 class="account-username"><a href="$mb.user.key">$mb.username</a> &rsaquo;</h2>
        </div>
        $if mb.key == 'list':
          <h1 class="details-title">$header_title</h1>
        $else:
          <div class="sansserif grey account-settings-menu navigation-breadcrumbs">
            $:render_template("books/mybooks_breadcrumb_select", mb, selected=header_title)
            $if header_title=="Already Read" and mb.reading_goals:

              $ selected_year = mb.selected_year if mb.selected_year else _("All Time")
              $:render_template("books/year_breadcrumb_select", mb, selected= selected_year)

          </div>
      </div>

      $if not mb.is_my_page and mb.is_subscribed != -1:
        $:macros.Follow(mb.username, following=mb.is_subscribed)

      $if 'followers' in mb.counts:
        <div class="social-wrapper">
          <a class="cta-btn cta-btn--unstyled" href="$(mb.user.key)/following"><strong>$mb.counts['following']</strong> $_("Following")</a>
          <a class="cta-btn cta-btn--unstyled" href="$(mb.user.key)/followers"><strong>$mb.counts['followers']</strong> $_("Followers")</a>
          $if mb.is_public and mb.key in mb.PUBLIC_KEYS:
            $set_share_links(url=request.canonical_url, title=header_title, view_context=ctx)
            $if ctx.get('share_links'):
              $ share_str = _('Share')
              $ share_content = '<a class="cta-btn cta-btn--unstyled share-modal-link icon-link" href="javascript:;" data-ol-link-track="MyBooksModalLinkClick|ShareIcon"><img class="icon-link__image" src="/static/images/icons/share.svg" width="20" alt=""> %s</a>' % share_str
              $ page_url = request.home
              $ share_links = ctx.get('share_links')
              $:macros.ShareModal(share_links, page_url, share_content, "share-modal-wrapper", show_embed=False)
        </div>
      $if page and mb.is_my_page:
        $:macros.databarView(page)
    </header>

    $ mb.component_times['Details header'] = time() - mb.component_times['Details header']
    $ mb.component_times['Details content'] = time()
    <div class="details-content">
      $if mb.is_my_page:
        $:render_template("account/topmenu", mb)

      $if mb.is_my_page and mb.key in ['notes', 'observations']:
        <p>
          $if mb.key == 'notes':
            $_('Your book notes are private and cannot be viewed by other patrons.')
          $elif mb.key == 'observations':
            $_('Your book reviews will be shared anonymously with other patrons.')
        </p>

      $if template:
        $:template
    </div>
    $ mb.component_times['Details content'] = time() - mb.component_times['Details content']
  </div>
</div>

$ mb.component_times['TotalTime'] = time() - mb.component_times['TotalTime']
$if query_param('debug'):
  $:macros.Profile(mb.component_times)
